/*
 *          PassThrough.glsl
 *
 *      Deferred buffering
 *
 */

//------------------------------------------------------------------------------


-- Vertex


// IN
layout(location = 0) in vec4 inPosition;
layout(location = 1) in vec2 inTexCoord;
layout(location = 2) in vec3 inNormal;

// OUT
out vec2 vTexCoord;
out vec3 vNormalVS;

// UNIFORM
uniform mat4 uModelViewProjMatrix;
uniform mat3 uNormalViewMatrix;


void main()
{
  gl_Position = uModelViewProjMatrix * inPosition;
  
  vTexCoord = inTexCoord;
  
  // compute normal in view-space
  vNormalVS = uNormalViewMatrix * inNormal;
}


--

//------------------------------------------------------------------------------


-- Fragment

// IN
in vec2 vTexCoord;
in vec3 vNormalVS;

// OUT
layout(location = 0) out vec4 fragDiffuse;
layout(location = 1) out vec3 fragNormal;
layout(location = 2) out vec3 fragMotionDoF;

// UNIFORM
uniform vec3 uColor = vec3(1.0f);
uniform sampler2D uTexture;
uniform bool uEnableTexturing = false;


void main()
{
  // == Diffuse Buffer == 
  fragDiffuse = vec4( uColor, 1.0f);
   
  if (uEnableTexturing) {
    fragDiffuse = texture( uTexture, vTexCoord);
  }

  
  // == Normal Buffer ==
  // [ TODO: Store only the XY component and retrieve the Z later ]
  // works when CullFace enables (to avoid z-fighting jaggies)
  fragNormal = (gl_FrontFacing) ? vNormalVS : -vNormalVS; 
  fragNormal = normalize(fragNormal);
    
  
  // == Motion / DoF Buffer ==
  fragMotionDoF = vec3(0.0f);
}

